home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / comm / mail / YAM22src.lha / YAM_ER.c < prev    next >
C/C++ Source or Header  |  2000-11-03  |  6KB  |  148 lines

  1. /***************************************************************************
  2.  
  3.  YAM - Yet Another Mailer
  4.  Copyright (C) 2000  Marcel Beck <mbeck@yam.ch>
  5.  
  6.  This program is free software; you can redistribute it and/or modify
  7.  it under the terms of the GNU General Public License as published by
  8.  the Free Software Foundation; either version 2 of the License, or
  9.  (at your option) any later version.
  10.  
  11.  This program is distributed in the hope that it will be useful,
  12.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  GNU General Public License for more details.
  15.  
  16.  You should have received a copy of the GNU General Public License
  17.  along with this program; if not, write to the Free Software
  18.  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20.  YAM Official Support Site :  http://www.yam.ch
  21.  YAM OpenSource project    :  http://sourceforge.net/projects/yamos/
  22.  
  23. ***************************************************************************/
  24.  
  25. #include "YAM.h"
  26.  
  27. /***************************************************************************
  28.  Module: Error window
  29. ***************************************************************************/
  30.  
  31. /// ER_NewError
  32. //  Adds a new error message and displays it
  33. void ER_NewError(char *error, char *arg1, char *arg2)
  34. {
  35.    static char label[SIZE_SMALL];
  36.    char buf[SIZE_LARGE];
  37.    struct ER_GUIData *gui;
  38.    int i;
  39.  
  40.    G->Error = TRUE;
  41.    if (!G->ER)
  42.    {
  43.       if (!(G->ER = ER_New())) return;
  44.       if (!SafeOpenWindow(G->ER->GUI.WI)) { DisposeModule(&G->ER); return; }
  45.    }
  46.    gui = &(G->ER->GUI);
  47.    if (error)
  48.    {
  49.       if (++G->ER_NumErr > MAXERR)
  50.       {
  51.          free(G->ER_Message[0]);
  52.          for (--G->ER_NumErr, i = 1; i < G->ER_NumErr; i++) G->ER_Message[i-1] = G->ER_Message[i];
  53.       }
  54.       sprintf(buf, error, arg1, arg2); strcat(buf, "\n\n(");
  55. //      strcat(buf, DateStamp2String(NULL, DSS_DATE)); strcat(buf, " ");
  56. //      strcat(buf, DateStamp2String(NULL, DSS_TIME)); strcat(buf, ")");
  57.       strcat(buf, DateStamp2String(NULL, C->SwatchBeat ? DSS_DATEBEAT : DSS_DATETIME));
  58.       strcat(buf, ")");
  59.       strcpy(G->ER_Message[G->ER_NumErr-1] = malloc(strlen(buf)+1), buf);
  60.    }
  61.    sprintf(label, "\033c%s %%ld/%ld", GetStr(MSG_ErrorReq), G->ER_NumErr);
  62.    set(gui->NB_ERROR, MUIA_Numeric_Format, label);
  63.    set(gui->NB_ERROR, MUIA_Numeric_Min, 1);
  64.    set(gui->NB_ERROR, MUIA_Numeric_Max, G->ER_NumErr);
  65.    set(gui->NB_ERROR, MUIA_Numeric_Value, G->ER_NumErr);
  66.    if (G->MA) set(G->MA->GUI.MI_ERRORS, MUIA_Menuitem_Enabled, TRUE);
  67. }
  68. ///
  69. /// ER_SelectFunc
  70. //  Displays an earlier error message
  71. SAVEDS ASM void ER_SelectFunc(REG(a1) int *arg)
  72. {
  73.    int value = *arg;
  74.    set(G->ER->GUI.BT_NEXT, MUIA_Disabled, value == G->ER_NumErr);
  75.    set(G->ER->GUI.BT_PREV, MUIA_Disabled, value == 1);
  76.    set(G->ER->GUI.LV_ERROR, MUIA_Floattext_Text, G->ER_Message[value-1]);
  77. }
  78. MakeHook(ER_SelectHook, ER_SelectFunc);
  79. ///
  80. /// ER_CloseFunc
  81. //  Closes error window
  82. SAVEDS ASM void ER_CloseFunc(REG(a1) int *arg)
  83. {
  84.    set(G->ER->GUI.WI, MUIA_Window_Open, FALSE);
  85.    if (*arg)
  86.    {
  87.       while (G->ER_NumErr) free(G->ER_Message[--G->ER_NumErr]);
  88.       if (G->MA) set(G->MA->GUI.MI_ERRORS, MUIA_Menuitem_Enabled, FALSE);
  89.    }
  90.    DisposeModulePush(&G->ER);
  91. }
  92. MakeHook(ER_CloseHook, ER_CloseFunc);
  93. ///
  94.  
  95. /*** GUI***/
  96. /// ER_New
  97. //  Creates error window
  98. struct ER_ClassData *ER_New(void)
  99. {
  100.    struct ER_ClassData *data;
  101.  
  102.    if (data = calloc(1,sizeof(struct ER_ClassData)))
  103.    {
  104.       APTR bt_close, bt_clear;
  105.       data->GUI.WI = WindowObject,
  106.          MUIA_Window_Title, GetStr(MSG_ER_ErrorMessages),
  107.          MUIA_Window_ID, MAKE_ID('E','R','R','O'),
  108.          WindowContents, VGroup,
  109.             Child, HGroup,
  110.                Child, data->GUI.BT_PREV = MakeButton(GetStr(MSG_ER_PrevError)),
  111.                Child, data->GUI.NB_ERROR = NumericbuttonObject,
  112.                   MUIA_Numeric_Min, 0,
  113.                   MUIA_Numeric_Value, 0,
  114.                   MUIA_Numeric_Format, "Error %%ld/%ld",
  115.                   MUIA_CycleChain, TRUE,
  116.                End,
  117.                Child, data->GUI.BT_NEXT = MakeButton(GetStr(MSG_ER_NextError)),
  118.             End,
  119.             Child, ListviewObject,
  120.                MUIA_Listview_Input, FALSE,
  121.                MUIA_CycleChain, 1,
  122.                MUIA_Listview_List, data->GUI.LV_ERROR = FloattextObject,
  123.                   ReadListFrame,
  124.                End,
  125.             End,
  126.             Child, ColGroup(2),
  127.                Child, bt_clear = MakeButton(GetStr(MSG_ER_Clear)),
  128.                Child, bt_close = MakeButton(GetStr(MSG_ER_Close)),
  129.             End,
  130.          End,
  131.       End;
  132.       if (data->GUI.WI)
  133.       {
  134.          DoMethod(G->App, OM_ADDMEMBER, data->GUI.WI);
  135.          DoMethod(data->GUI.BT_PREV ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,data->GUI.NB_ERROR     ,2,MUIM_Numeric_Decrease,1);
  136.          DoMethod(data->GUI.BT_NEXT ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,data->GUI.NB_ERROR     ,2,MUIM_Numeric_Increase,1);
  137.          DoMethod(data->GUI.NB_ERROR,MUIM_Notify,MUIA_Numeric_Value      ,MUIV_EveryTime,MUIV_Notify_Application,3,MUIM_CallHook,&ER_SelectHook,MUIV_TriggerValue);
  138.          DoMethod(bt_clear          ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,MUIV_Notify_Application,3,MUIM_CallHook,&ER_CloseHook,TRUE);
  139.          DoMethod(bt_close          ,MUIM_Notify,MUIA_Pressed            ,FALSE         ,MUIV_Notify_Application,3,MUIM_CallHook,&ER_CloseHook,FALSE);
  140.          DoMethod(data->GUI.WI      ,MUIM_Notify,MUIA_Window_CloseRequest,TRUE          ,MUIV_Notify_Application,3,MUIM_CallHook,&ER_CloseHook,FALSE);
  141.          return data;
  142.       }
  143.       free(data);
  144.    }
  145.    return NULL;
  146. }
  147. ///
  148.